<template>

        <div class="iframe-container">
            <div>正在拉取支付宝支付，若许久没跳转，请<el-button @click="loadPaymentIframe()" link type="primary" >点我</el-button>尝试</div>
            <div id="payment-div"></div>
        </div>


</template>

<script setup lang="ts">
import { ref, onMounted,defineProps } from 'vue'
import request from '@/base/request'
import { ElMessage } from 'element-plus'

const loading = ref(true)

const props = defineProps<{
    orderStatementId: string
}>()
onMounted(() => {
    loadPaymentIframe()
})

// 加载支付iframe
const loadPaymentIframe = async () => {
    loading.value = true
    try {
        const response = await request.get('/trade/orderStatement/tryToPay', {
            params: {
                orderStatementId: props.orderStatementId
            }
        })
        
        if (response.data.code === 200 && response.data.data) {
            console.log(response.data.data)
            document.getElementById('payment-div').innerHTML = response.data.data;
            document.forms[0].submit(); 
        } else {
            ElMessage.error(response.data.msg || '获取支付信息失败')
        }
    } catch (error) {
        console.log(error)
        ElMessage.error('获取支付信息失败，请稍后重试')
    } finally {
        loading.value = false
    }
}
</script>

<style scoped>
.payment-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background-color: #1d1e1f;
    color: #e5eaf3;
}

.payment-content {
    width: 100%;
    max-width: 800px;
    background-color: #2b2b2c;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    border: 1px solid #363637;
}

.payment-title {
    text-align: center;
    margin-bottom: 30px;
    font-size: 24px;
    font-weight: 600;
    color: #e5eaf3;
}

.payment-info {
    margin-bottom: 30px;
    padding: 15px;
    background-color: #1d1e1f;
    border-radius: 8px;
    border: 1px solid #363637;
}

.payment-info p {
    margin: 10px 0;
    font-size: 16px;
}

.iframe-container {
    width: 100%;
    height: 500px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #363637;
}

.payment-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.payment-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 40px 0;
}

@media (max-width: 768px) {
    .payment-content {
        padding: 20px;
    }
    
    .iframe-container {
        height: 400px;
    }
}
</style> 